package com.peng.stack_queue.array;

public class Stack {

    private int index;
    private int[] arr;
    private int maxSize;

    public Stack(int maxSize) {
        this.maxSize = maxSize;
        this.arr = new int[maxSize];
    }

    public void push(int val){
        if(index== maxSize){
            throw new RuntimeException("stack已满！！");
        }

        arr[index++] = val;
    }

    public int pop(){
        if(index ==0){
            throw new RuntimeException("stack已空，弹不出拉！！");
        }
        return arr[--index];

    }

    public static void main(String[] args) {
        Stack stack = new Stack(5);
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        stack.push(5);
        System.out.println(stack.pop());

        stack.push(5);
        stack.push(5);
        System.out.println(stack.pop());
    }

}
